package com.kamikaze;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class Modification_AllServlet
 */
public class Modification_AllServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Modification_AllServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String user_id = request.getParameter("user_id");
		String user_pw = request.getParameter("user_pw");
		String user_name = request.getParameter("user_name");
		String user_gender = request.getParameter("user_gender");
		String user_birthday = request.getParameter("user_birthday");
		String user_employee = request.getParameter("user_employee");
		String user_tel = request.getParameter("user_tel");
		String user_mobile = request.getParameter("user_mobile");
		String user_address = request.getParameter("user_address");
		String user_salary = request.getParameter("user_salary");
		String dept_number = request.getParameter("dept_number");
		String user_level = request.getParameter("user_level");
		String user_image = request.getParameter("user_image");
		Member member = new Member(user_id, user_pw);
		// 取得修改的欄位

		Modification mod = new Modification(user_pw, user_name, user_gender,
				user_birthday, user_employee, user_tel, user_mobile,
				user_address, user_salary, dept_number, user_level, user_image);
		session.setAttribute("Modification", mod);
		// 取得登入的欄位
		if (!member.login() && dept_number.equals('1')) {
			response.sendRedirect("view.jsp");
			if (mod.updateall()) {
				// 修改成功後要轉址?
				System.out.println("修改成功");
			}
		} else {
			response.sendRedirect("login.jsp");
		}

	}
}
